-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: enabling safe functions in expression engine #5403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
allowing toLowerCase(), replace(), and split() to be used in the expression editor. https://discord.com/channels/955905230107738152/1418928616648998992/1419623805541814393
|
My only wish is that we would support the entire js there and not a few functions, because:
|
|
I'd love webstudio to support the entire js in the expression editor! |
That's a fair point. A random list of functions is confusing, and you're right, people will always wonder why one thing works and another doesn't. The problem with allowing everything is the security risk, right? Stuff like So what if we set a clear rule for what's allowed? We could support all the standard methods on primitives (Strings, Arrays, etc.) as long as they don't mutate the original data. That way, it feels like you're just writing JavaScript for data manipulation. Methods like My PR for What do you think? I'm happy to expand the PR to include more of these "safe" methods if you agree on this as the general rule. |
…y methods This pull request enhances the expression engine to support a curated list of safe, non-mutating methods on the String and Array prototypes.
added optional chaining and additional tests.
|
do you want me to change anything else? |
|
All good. We were just a occupied with inception recently. Though you can try to add autocomplete for these methods if you want. |
|
Yes, maybe even with parentheses for clarity like this |
|
Btw I will merge this. You can start new PR |
|
Thanks! |
|
Good job @zehjotkah ! |
## Description Added autocomplete support for safe string and array methods in the expression editor, as suggested by @TrySound in PR #5403. ## Changes - Exported `allowedStringMethods` and `allowedArrayMethods` from `packages/sdk/src/expression.ts` - Enhanced the expression editor's autocomplete to suggest safe methods when typing after a variable (e.g., system) - Methods are displayed with parentheses for clarity (e.g., `toLowerCase()`, `replace()`, `split()`) - Autocomplete shows helpful labels: "string method" or "array method" ## How to Test 1. Open any project in the builder 2. Click the expression editor icon next to a text property 3. Type a variable name followed by a dot (e.g., `system.`) 4. You should see autocomplete suggestions for safe string methods like `toLowerCase()`, `replace()`, `split()`, etc. 5. Type a few letters to filter (e.g., `title.to` shows only methods starting with "to") 6. Select a method and it will be inserted with parentheses ## Related - Builds on PR #5403 which enabled these safe methods in the expression engine <img width="343" height="204" alt="Bildschirmfoto 2025-10-09 um 22 33 03" src="https://github.com/user-attachments/assets/206a36e8-1d68-4e2a-a045-1f9e95067a28" />

Description
allowing toLowerCase(), replace(), and split() to be used in the expression editor.
Real life use-case explained in the discord message.
https://discord.com/channels/955905230107738152/1418928616648998992/1419623805541814393
Steps for reproduction
-> validation check bypass
Code Review
Before requesting a review
Before merging
.envfile